#! /usr/bin/python

import webbrowser, subprocess, datetime, Tkinter, os, threading
import xml.dom.minidom

def add_entry():
	global index_no,doc, issue, title_text_tk, descrip_text_tk
	 
	title_str = title_text_tk.get(1.0, Tkinter.END)
	descrip_str = descrip_text_tk.get(1.0, Tkinter.END)
	
	# Create the main <subject> element
	subject = doc.createElement("subject")
	subject.setAttribute("id", str(index_no))
	issue.appendChild(subject)
	
	# Create a <Title> element
	title_text = doc.createElement("Title")
	subject.appendChild(title_text)
	# Give the <Title> elemenet the text
	t_text = doc.createTextNode(title_str)
	title_text.appendChild(t_text)

	# Create a <Descript> element
	descript_text = doc.createElement("Descript")
	subject.appendChild(descript_text)
	# Give the <Descript> elemenet the text
	p_text = doc.createTextNode(descrip_str)
	descript_text.appendChild(p_text)
	
	index_no = index_no + 1
	
def complete_entry():
	global doc
	# Print the created XML
	result = doc.toprettyxml(indent="  ")
	file = open('issue.xml', mode='w')
	file.write(result)
	file.close()
	
if __name__ == '__main__':

	root = Tkinter.Tk()

	#Top Frame 
	top_frame = Tkinter.Frame(root)
	top_frame.pack(side=Tkinter.TOP)
	
	title_text_tk = Tkinter.Text(top_frame,width=70, height=5, font=("Helvetica", 16))
	title_text_tk.pack(side=Tkinter.LEFT)
	
	btn_add_tk = Tkinter.Button(top_frame, text='Add', command=add_entry)
	btn_add_tk.pack(side=Tkinter.LEFT)
	
	btn_complete_tk = Tkinter.Button(top_frame, text='Complete', command=complete_entry)
	btn_complete_tk.pack(side=Tkinter.LEFT)
	
	# Bottom Frame
	btn_frame = Tkinter.Frame(root)
	btn_frame.pack(side=Tkinter.BOTTOM)
	
	descrip_text_tk = Tkinter.Text(btn_frame,width=60, height=8, font=("Helvetica", 14))
	descrip_text_tk.pack(side=Tkinter.RIGHT)
	
	doc=xml.dom.minidom.Document()
	# Create the <issue> base element
	issue = doc.createElement("issue")
	doc.appendChild(issue)

	index_no = 0
	
	root.mainloop()
